import 'monaco-editor';
import editorWorker from 'monaco-editor/esm/vs/editor/editor.worker?worker'
import jsonWorker from 'monaco-editor/esm/vs/language/json/json.worker?worker'
import tsWorker from 'monaco-editor/esm/vs/language/typescript/ts.worker?worker'
import htmlWorker from 'monaco-editor/esm/vs/language/html/html.worker?worker'
import cssWorker from 'monaco-editor/esm/vs/language/css/css.worker?worker'

export const editorOption = {
  // 是否启用预览图
  minimap: { enabled: false },
  // 圆角
  roundedSelection: true,
  // 主题
  theme: 'vs-dark',
  // 主键
  multiCursorModifier: 'ctrlCmd',
  // 滚动条
  scrollbar: {
    verticalScrollbarSize: 8,
    horizontalScrollbarSize: 8
  },
  // 行号
  lineNumbers: 'off',
  // tab大小
  tabSize: 2,
  //字体大小
  fontSize: 16,
  // 控制编辑器在用户键入、粘贴、移动或缩进行时是否应自动调整缩进
  autoIndent: 'advanced',
  // 自动布局
  automaticLayout: true
}

/**
 * 创建monaca环境
 */
export function createEv() {
  if(self.MonacoEnvironment?.getWorker) return
  self.MonacoEnvironment = {
    getWorker(workerId, label) {
      if (label === 'json') {
        return new jsonWorker()
      }
      if (label === 'typescript' || label === 'javascript') {
        return new tsWorker()
      }
      if (label === 'html') {
        return new htmlWorker()
      }
      if (label === 'css') {
        return new cssWorker()
      }
      return new editorWorker()
    }
  }
}
